//
//  YIMServer.swift
//  YIM
//
//  Created by YMac on 09/02/2022.
//  Copyright © 2022 zchd. All rights reserved.
//
import Foundation
import SocketIO
import ObjectBox

internal class sYYOQcJgzfspJCWn: NSObject {
    var jqKudqmHVDVUDDZz:((YIMResult<YIMEnum_LoginResult>) throws -> Void)?
    var BNcDeXiMYIkxTcTE: SocketIOClient?
    var XvWTOCbAcOIAGANr: SocketManager?
    var wOCQTtzPfFAecGcz: Timer?
    var ZOMPrIKAysGeUPVu: Timer?
    var ASVAGVbveLxXloVY = false
    var rLTFfRkpMUgLkyFW: String?
    var hirkcafJoWWFnAjp = false
    
    let gcDwQgisPaYpamBp = 1
    var zPbXZaKCTaAnQWRC = ""

    func qUronpQwkCUHNjmf(UhzaNhigkZjxYKFZ:String, TxzdMHVHmUVisByn:String, lnPbkmdwNECDwBnh: ((YIMResult<YIMEnum_LoginResult>) throws -> Void)? = nil) {
        if NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG != nil {
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? lnPbkmdwNECDwBnh?(YIMResult(VnJfdRrzZmdnJmsc: .Exception, EmqetgaKELbCTYMP: "Repeated login"))
            }
            return
        }
        ASVAGVbveLxXloVY = false
        hirkcafJoWWFnAjp = false
        self.jqKudqmHVDVUDDZz = lnPbkmdwNECDwBnh
        NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG = UhzaNhigkZjxYKFZ
        rLTFfRkpMUgLkyFW = TxzdMHVHmUVisByn
        eFgNVOpBmPmJhaCd(zUpYHyCUqzVsBFgF: false)
        LkgSnkYUgjMmCowc(zUpYHyCUqzVsBFgF: false)
        ZOMPrIKAysGeUPVu = Timer.scheduledTimer(withTimeInterval: NbDnvbpESqnqDInl.SoORWivnNfUskmhc.tSfLUACOkywsUJFE, repeats: false) { _ in
            self.jfhCUDILPQnkSyQg(kEZOdhLcNmJFYywX: "loginFailed", EeqbYNIBaZfkqYaF: ["msg" : "time out"])
        }
    }
    
    func LkgSnkYUgjMmCowc(zUpYHyCUqzVsBFgF: Bool) {
        XvWTOCbAcOIAGANr = SocketManager(socketURL: URL(string: "\(NbDnvbpESqnqDInl.SoORWivnNfUskmhc.ZSgCfzHnxpKhZfxO)")!)
        XvWTOCbAcOIAGANr!.config.insert(.forceWebsockets(true))
        XvWTOCbAcOIAGANr!.config.insert(.reconnects(false))
        XvWTOCbAcOIAGANr!.config.insert(.log(false))
        XvWTOCbAcOIAGANr!.config.insert(.connectParams([
            "query": NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.VBxorykRlBCVhSNZ(IMuPBNSVQxljIWnu: NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.xtovshfHwqTsyirV([
                "accid": NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG!,
                "token": rLTFfRkpMUgLkyFW!,
                "appKey": NbDnvbpESqnqDInl.HNMTEjFdjzjxYWYx?.appKey ?? "",
                "device": "ios",
                "isReconnect": zUpYHyCUqzVsBFgF ? "1" : "0",
                "version": NbDnvbpESqnqDInl.SoORWivnNfUskmhc.TILoKkmTdSCUnmfH,
                "packageName": Bundle.main.bundleIdentifier ?? "",
            ]))
        ]))
        XvWTOCbAcOIAGANr!.config.insert(.version(.two))
        BNcDeXiMYIkxTcTE = XvWTOCbAcOIAGANr!.defaultSocket
        BNcDeXiMYIkxTcTE!.on(clientEvent: .connect) { EeqbYNIBaZfkqYaF, ZvuYFkqwzuOckYvg in NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.aKdyLQPwRZgdzpAx(IMuPBNSVQxljIWnu: "onConnect") }
        BNcDeXiMYIkxTcTE!.on(clientEvent: .reconnect) { EeqbYNIBaZfkqYaF, ZvuYFkqwzuOckYvg in NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.aKdyLQPwRZgdzpAx(IMuPBNSVQxljIWnu: "onReconnect") }
        BNcDeXiMYIkxTcTE!.on("connecting") { EeqbYNIBaZfkqYaF, ZvuYFkqwzuOckYvg in NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.aKdyLQPwRZgdzpAx(IMuPBNSVQxljIWnu: "onConnecting") }
        BNcDeXiMYIkxTcTE!.on("connect_timeout") { EeqbYNIBaZfkqYaF, ZvuYFkqwzuOckYvg in NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.aKdyLQPwRZgdzpAx(IMuPBNSVQxljIWnu: "onConnectTimeout") }
        BNcDeXiMYIkxTcTE!.on("connect_error") { EeqbYNIBaZfkqYaF, ZvuYFkqwzuOckYvg in NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.aKdyLQPwRZgdzpAx(IMuPBNSVQxljIWnu: "onConnectError") }
        BNcDeXiMYIkxTcTE!.on(clientEvent: .error) { EeqbYNIBaZfkqYaF, ZvuYFkqwzuOckYvg in NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.aKdyLQPwRZgdzpAx(IMuPBNSVQxljIWnu: "onError:\(EeqbYNIBaZfkqYaF)") }
        BNcDeXiMYIkxTcTE!.on(clientEvent: .disconnect) { EeqbYNIBaZfkqYaF, ZvuYFkqwzuOckYvg in
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.aKdyLQPwRZgdzpAx(IMuPBNSVQxljIWnu: "onDisconnect: \(EeqbYNIBaZfkqYaF)")
            self.xmrApjdylynieJgP(QWgDujAUvfAGYENs: "\(EeqbYNIBaZfkqYaF)")
        }
        BNcDeXiMYIkxTcTE!.on("server") { EeqbYNIBaZfkqYaF, ZvuYFkqwzuOckYvg in
            let kKsxeMWRvxOisRhl = EeqbYNIBaZfkqYaF.first(where: {
                $0 is [String: Any]
            }) as! [String: Any]
            let IMuPBNSVQxljIWnu = NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.GkNTaCvzlvcowaSg(NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.epGrfPUosodDOBQU(IMuPBNSVQxljIWnu: kKsxeMWRvxOisRhl["content"] as! String))!
            self.jfhCUDILPQnkSyQg(kEZOdhLcNmJFYywX: IMuPBNSVQxljIWnu["event"] as! String, EeqbYNIBaZfkqYaF: IMuPBNSVQxljIWnu["data"] as! [String: Any])
        }
        BNcDeXiMYIkxTcTE!.connect()
    }

    func etDatGyKwukGrbHv(
        kEZOdhLcNmJFYywX: String,
        EeqbYNIBaZfkqYaF: Any? = [:],
        zUpYHyCUqzVsBFgF: Bool = false,
        lQAqmDEBwPYyDmPF: ((_ mKUIzAxlvBGUVfVk:Bool, _ EyTIVrNCTVqmYwPu:[String: Any]?, _ VnJfdRrzZmdnJmsc:Int, _ EmqetgaKELbCTYMP:String) throws -> Void)? = nil
    ) {
        NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.aKdyLQPwRZgdzpAx(IMuPBNSVQxljIWnu: "[emit_request]: \n\tevent: \(kEZOdhLcNmJFYywX)\n\tdata: \(NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.xtovshfHwqTsyirV(EeqbYNIBaZfkqYaF ?? [:]))")
        var PZZKHkKZnriOzGPi = false
        do {
            if !fZwNztHkPUvazdeo.kKZHQgqVvWvEzcze.CJpHDPXJovTfKuUn() {
                if PZZKHkKZnriOzGPi { return }
                PZZKHkKZnriOzGPi = true
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.aKdyLQPwRZgdzpAx(IMuPBNSVQxljIWnu: "[emit_response_cancel]: \n\tevent: \(kEZOdhLcNmJFYywX)")
                try lQAqmDEBwPYyDmPF?(false, nil, 0, "Please login first!")
                return
            }
            if !fZwNztHkPUvazdeo.kKZHQgqVvWvEzcze.CJpHDPXJovTfKuUn(bAviYiLBLceXSWgD: true) {
                if PZZKHkKZnriOzGPi { return }
                PZZKHkKZnriOzGPi = true
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.aKdyLQPwRZgdzpAx(IMuPBNSVQxljIWnu: "[emit_response_cancel]: \n\tevent: \(kEZOdhLcNmJFYywX)")
                if zUpYHyCUqzVsBFgF {
                    try lQAqmDEBwPYyDmPF?(false, nil, 0, "has not connected, try again later!")
                } else {
                    Timer.scheduledTimer(withTimeInterval: TimeInterval(9), repeats: false) { _ in
                        self.etDatGyKwukGrbHv(kEZOdhLcNmJFYywX: kEZOdhLcNmJFYywX, EeqbYNIBaZfkqYaF: EeqbYNIBaZfkqYaF, zUpYHyCUqzVsBFgF: true, lQAqmDEBwPYyDmPF: lQAqmDEBwPYyDmPF)
                    }
                }
                return
            }
            Timer.scheduledTimer(withTimeInterval: TimeInterval(NbDnvbpESqnqDInl.SoORWivnNfUskmhc.tSfLUACOkywsUJFE), repeats: false) { _ in
                if PZZKHkKZnriOzGPi { return }
                PZZKHkKZnriOzGPi = true
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.aKdyLQPwRZgdzpAx(IMuPBNSVQxljIWnu: "[emit_response_timeout]: \n\tevent: \(kEZOdhLcNmJFYywX)")
                try? lQAqmDEBwPYyDmPF?(false, nil, 0, "[\(kEZOdhLcNmJFYywX)] time out")
            }
            BNcDeXiMYIkxTcTE?.emitWithAck("client", with: [[
                "content": NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.VBxorykRlBCVhSNZ(IMuPBNSVQxljIWnu: NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.xtovshfHwqTsyirV([
                    "event" : kEZOdhLcNmJFYywX,
                    "data": EeqbYNIBaZfkqYaF ?? [:],
                ]))
            ]]).timingOut(after: .zero) { EeqbYNIBaZfkqYaF in
                do {
                    var EyTIVrNCTVqmYwPu = EeqbYNIBaZfkqYaF.first as? [String: Any]
                    if EyTIVrNCTVqmYwPu == nil {
                        if PZZKHkKZnriOzGPi { return }
                        PZZKHkKZnriOzGPi = true
                        NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.aKdyLQPwRZgdzpAx(IMuPBNSVQxljIWnu: "[emit_response_null]: \n\tevent: \(kEZOdhLcNmJFYywX)")
                        try? lQAqmDEBwPYyDmPF?(false, nil, 0, "null response")
                        return
                    }
                    if PZZKHkKZnriOzGPi { return }
                    PZZKHkKZnriOzGPi = true
                    let VnJfdRrzZmdnJmsc = EyTIVrNCTVqmYwPu!["code"] as! Int
                    let mKUIzAxlvBGUVfVk = (VnJfdRrzZmdnJmsc == 200)
                    let EmqetgaKELbCTYMP = (EyTIVrNCTVqmYwPu!["msg"] as? String) ?? ""
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.aKdyLQPwRZgdzpAx(IMuPBNSVQxljIWnu: "[emit_response_success]: \n\tevent: \(kEZOdhLcNmJFYywX)\n\tdata: \(NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.xtovshfHwqTsyirV(EyTIVrNCTVqmYwPu!))")
                    EyTIVrNCTVqmYwPu!.removeValue(forKey: "code")
                    EyTIVrNCTVqmYwPu!.removeValue(forKey: "msg")
                    try lQAqmDEBwPYyDmPF?(mKUIzAxlvBGUVfVk, EyTIVrNCTVqmYwPu!["data"] as? [String: Any], VnJfdRrzZmdnJmsc, EmqetgaKELbCTYMP)
                } catch {
                    if PZZKHkKZnriOzGPi { return }
                    PZZKHkKZnriOzGPi = true
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.aKdyLQPwRZgdzpAx(IMuPBNSVQxljIWnu: "[emit_response_success]: \n\tevent: \(kEZOdhLcNmJFYywX)\n\terror: \(error.localizedDescription)")
                    try? lQAqmDEBwPYyDmPF?(false, nil, 0, "Exception: \(error.localizedDescription)")
                }
            }
        } catch {
            if PZZKHkKZnriOzGPi { return }
            PZZKHkKZnriOzGPi = true
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.aKdyLQPwRZgdzpAx(IMuPBNSVQxljIWnu: "[emit_response_exception]: \n\tevent: \(kEZOdhLcNmJFYywX)\n\terror: \(error.localizedDescription)")
            try? lQAqmDEBwPYyDmPF?(false, nil, 0, "Exception: \(error.localizedDescription)")
        }
    }

    func eFgNVOpBmPmJhaCd(zUpYHyCUqzVsBFgF: Bool) {
        func hdKUpfMGlTKOYWpW(){
            BNcDeXiMYIkxTcTE?.off(clientEvent: .connect)
            BNcDeXiMYIkxTcTE?.off(clientEvent: .reconnect)
            BNcDeXiMYIkxTcTE?.off("connecting")
            BNcDeXiMYIkxTcTE?.off("connect_timeout")
            BNcDeXiMYIkxTcTE?.off("connect_error")
            BNcDeXiMYIkxTcTE?.off(clientEvent: .error)
            BNcDeXiMYIkxTcTE?.off(clientEvent: .disconnect)
            BNcDeXiMYIkxTcTE?.off("server")
            BNcDeXiMYIkxTcTE?.disconnect()
            BNcDeXiMYIkxTcTE = nil
            XvWTOCbAcOIAGANr?.disconnect()
            XvWTOCbAcOIAGANr = nil
        }
        if zUpYHyCUqzVsBFgF {
            hdKUpfMGlTKOYWpW()
        } else {
//            currentToken = nil
            wOCQTtzPfFAecGcz?.invalidate()
            wOCQTtzPfFAecGcz = nil
            ZOMPrIKAysGeUPVu?.invalidate()
            ZOMPrIKAysGeUPVu = nil
            hdKUpfMGlTKOYWpW()
        }
    }

    func xmrApjdylynieJgP(QWgDujAUvfAGYENs: String) {
        if ASVAGVbveLxXloVY { return }
        ASVAGVbveLxXloVY = true
        fZwNztHkPUvazdeo.kKZHQgqVvWvEzcze.DASFOrpmVNSuuhGj()
        NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
            try? self.jqKudqmHVDVUDDZz?(YIMResult(VnJfdRrzZmdnJmsc: .Failed, EmqetgaKELbCTYMP: QWgDujAUvfAGYENs))
        }
        NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
            self.jqKudqmHVDVUDDZz = nil
        }
    }
    
    func uXffMnPluKsSLscV() {
        if fZwNztHkPUvazdeo.NKBRHVWrtACVYZIX.DWDZyFVwscgqplCs.isEmpty { return }
        //断线后，服务端会清空订阅清单，所以重连成功后，重新订阅
        fZwNztHkPUvazdeo.NKBRHVWrtACVYZIX.zBOikeFAKnUfELva(SxubugnXwQRzhFZG: Array(fZwNztHkPUvazdeo.NKBRHVWrtACVYZIX.DWDZyFVwscgqplCs), gGnEfsJvqSGuZGvh: { mKUIzAxlvBGUVfVk in
            if !mKUIzAxlvBGUVfVk {
                Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { _ in
                    self.uXffMnPluKsSLscV()
                }
            }
        }, VArUYFQhEOBgceOE: fZwNztHkPUvazdeo.NKBRHVWrtACVYZIX.qullakzWowrBAiuC!)
    }
    
    func jfhCUDILPQnkSyQg(kEZOdhLcNmJFYywX:String, EeqbYNIBaZfkqYaF:[String: Any]) {
        objc_sync_enter(gcDwQgisPaYpamBp)
        let lQnFfHagJZRapTwc = 2
        func jlvTeJlkZyPilZcK(GZRevkeIIdHLwXxe: YIMMessage, kaDklCkbYfRntgZy: Bool, lnPbkmdwNECDwBnh: ((_ mKUIzAxlvBGUVfVk: Bool) -> Void)? = nil) {
            objc_sync_enter(lQnFfHagJZRapTwc)
            if GZRevkeIIdHLwXxe.id == self.zPbXZaKCTaAnQWRC {
                objc_sync_exit(lQnFfHagJZRapTwc)
                return
            }
            self.zPbXZaKCTaAnQWRC = GZRevkeIIdHLwXxe.id
            switch GZRevkeIIdHLwXxe.conversationType {
            case .P2P:
                let hyridvHtGRONajzD = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.hyridvHtGRONajzD(_YIMTable_Message.self) {
                    _YIMTable_Message.id == GZRevkeIIdHLwXxe.id
                }
                if hyridvHtGRONajzD == nil {
                    lnPbkmdwNECDwBnh?(false)
                    return
                }
                if hyridvHtGRONajzD! > 0 {
                    lnPbkmdwNECDwBnh?(false)
                    return
                }
                let xjSWySxclwWCwOiY = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.KamiWNsKhqtzmVUX(_YIMTable_Message.self, EeqbYNIBaZfkqYaF: _YIMTable_Message(GZRevkeIIdHLwXxe: GZRevkeIIdHLwXxe))
                if !xjSWySxclwWCwOiY {
                    lnPbkmdwNECDwBnh?(false)
                    return
                }
                let drotiWAFkowcWbqO = fZwNztHkPUvazdeo.rDswoxpKBaqbcUtn.gTORhrTDtqcJUNpY(
                            uwnLgFlhpyfCLJAx: GZRevkeIIdHLwXxe.conversationType,
                            IYfxgmQIzqRJWEUV: GZRevkeIIdHLwXxe.from == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG ? GZRevkeIIdHLwXxe.to : GZRevkeIIdHLwXxe.from,
                            QfmrhidBvfBIkVBE: (GZRevkeIIdHLwXxe.from != NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG && GZRevkeIIdHLwXxe.messageState == .Success_UnRead) ? .KUZyxfTPYXbjmFmD : .duJIAxLvlDPyHEPt
                )
                if !drotiWAFkowcWbqO {
                    lnPbkmdwNECDwBnh?(false)
                    return
                }
                if kaDklCkbYfRntgZy {
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                        try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.OvGVkxnHBDrKREOn?([GZRevkeIIdHLwXxe])
                    }
                } else {
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                        try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.WOLubbPCZQvMqIdc?([GZRevkeIIdHLwXxe])
                    }
                }
                lnPbkmdwNECDwBnh?(true)
            case .Team:
                let hyridvHtGRONajzD = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.hyridvHtGRONajzD(_YIMTable_Message.self) {
                    _YIMTable_Message.id == GZRevkeIIdHLwXxe.id
                }
                if hyridvHtGRONajzD == nil {
                    lnPbkmdwNECDwBnh?(false)
                    return
                }
                if hyridvHtGRONajzD! > 0 {
                    lnPbkmdwNECDwBnh?(false)
                    return
                }
                let xjSWySxclwWCwOiY = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.KamiWNsKhqtzmVUX(_YIMTable_Message.self, EeqbYNIBaZfkqYaF: _YIMTable_Message(GZRevkeIIdHLwXxe: GZRevkeIIdHLwXxe))
                if !xjSWySxclwWCwOiY {
                    lnPbkmdwNECDwBnh?(false)
                    return
                }
                let drotiWAFkowcWbqO = fZwNztHkPUvazdeo.rDswoxpKBaqbcUtn.gTORhrTDtqcJUNpY(
                            uwnLgFlhpyfCLJAx: GZRevkeIIdHLwXxe.conversationType,
                            IYfxgmQIzqRJWEUV: GZRevkeIIdHLwXxe.to,
                            QfmrhidBvfBIkVBE: (GZRevkeIIdHLwXxe.from != NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG) ? .KUZyxfTPYXbjmFmD : .duJIAxLvlDPyHEPt
                )
                if !drotiWAFkowcWbqO {
                    lnPbkmdwNECDwBnh?(false)
                    return
                }
                if kaDklCkbYfRntgZy {
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                        try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.OvGVkxnHBDrKREOn?([GZRevkeIIdHLwXxe])
                    }
                } else {
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                        try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.WOLubbPCZQvMqIdc?([GZRevkeIIdHLwXxe])
                    }
                }
                lnPbkmdwNECDwBnh?(true)
            case .ChatRoom:
                if kaDklCkbYfRntgZy {
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                        try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.OvGVkxnHBDrKREOn?([GZRevkeIIdHLwXxe])
                    }
                } else {
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                        try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.WOLubbPCZQvMqIdc?([GZRevkeIIdHLwXxe])
                    }
                }
            default: break
            }
            objc_sync_exit(lQnFfHagJZRapTwc)
        }
        
        switch kEZOdhLcNmJFYywX {
        case "loginFailed":
            xmrApjdylynieJgP(QWgDujAUvfAGYENs: EeqbYNIBaZfkqYaF["msg"] as! String)
        case "loginSuccess":
            if ASVAGVbveLxXloVY { return }
            ASVAGVbveLxXloVY = true
            wOCQTtzPfFAecGcz?.invalidate()
            wOCQTtzPfFAecGcz = nil
            ZOMPrIKAysGeUPVu?.invalidate()
            ZOMPrIKAysGeUPVu = nil
            wOCQTtzPfFAecGcz = Timer.scheduledTimer(withTimeInterval: 5, repeats: true) { _ in
                if !fZwNztHkPUvazdeo.kKZHQgqVvWvEzcze.CJpHDPXJovTfKuUn(bAviYiLBLceXSWgD: true) {
                    if !self.hirkcafJoWWFnAjp {
                        self.hirkcafJoWWFnAjp = true
                        NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                            try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.XBgpCrYXyimOqEjN?(YIMResult(VnJfdRrzZmdnJmsc: .Reconnecting, EmqetgaKELbCTYMP: "Reconnecting"))
                        }
                        self.eFgNVOpBmPmJhaCd(zUpYHyCUqzVsBFgF: true)
                        Timer.scheduledTimer(withTimeInterval: 1, repeats: false) { _ in
                            self.LkgSnkYUgjMmCowc(zUpYHyCUqzVsBFgF: true)
                            Timer.scheduledTimer(withTimeInterval: 5, repeats: false) { _ in
                                if self.hirkcafJoWWFnAjp {
                                    self.hirkcafJoWWFnAjp = false
                                    self.eFgNVOpBmPmJhaCd(zUpYHyCUqzVsBFgF: true)
                                }
                            }
                        }
                    }
                } else {
                    if self.hirkcafJoWWFnAjp {
                        self.hirkcafJoWWFnAjp = false
                        self.uXffMnPluKsSLscV()
                        NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                            try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.XBgpCrYXyimOqEjN?(YIMResult(VnJfdRrzZmdnJmsc: .Reconnected, EmqetgaKELbCTYMP: "Reconnected"))
                        }
                    }
//                    NbDnvbpESqnqDInl.ZSgCfzHnxpKhZfxO.etDatGyKwukGrbHv(event:"refreshOnline")
                }
            }
            NbDnvbpESqnqDInl.ZPyrCbzOlbdctqkw = NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.IYMCIgmwfHIBQjIX(EeqbYNIBaZfkqYaF["user"], YIMUser.self)
            NbDnvbpESqnqDInl.rbtEkWTTnlkPCykk = (EeqbYNIBaZfkqYaF["conversationTops"] as! NSArray).map { $0 as! String }
            NbDnvbpESqnqDInl.CrqtQKnPpOIPqGjt = (EeqbYNIBaZfkqYaF["disturbs_p2p"] as! NSArray).map { $0 as! String }
            NbDnvbpESqnqDInl.vBnlRsjXyYsjAiyP = (EeqbYNIBaZfkqYaF["disturbs_team"] as! NSArray).map { $0 as! String }
            NbDnvbpESqnqDInl.hUaxJkdEfQCZrrHT.mBcRiYEyhdTTBqyF(EeqbYNIBaZfkqYaF: EeqbYNIBaZfkqYaF["oss"] as? [String: Any])
            NbDnvbpESqnqDInl.bgaUTCffvgrJbXZU.mBcRiYEyhdTTBqyF(EeqbYNIBaZfkqYaF: EeqbYNIBaZfkqYaF["push"] as? [String: Any?])
            //同步云端会话
            etDatGyKwukGrbHv(kEZOdhLcNmJFYywX: "queryConversations") { mKUIzAxlvBGUVfVk, EyTIVrNCTVqmYwPu, VnJfdRrzZmdnJmsc, EmqetgaKELbCTYMP in
                if mKUIzAxlvBGUVfVk {
                    var etjOVteRPjPtfhhi = EyTIVrNCTVqmYwPu?["conversations"] as? [[String: Any]]
                    if etjOVteRPjPtfhhi == nil || etjOVteRPjPtfhhi!.isEmpty { return }
                    fZwNztHkPUvazdeo.rDswoxpKBaqbcUtn.TEHrCcQWLqKUUweb { ormchpikGcmflTHU in
                        //过滤本地已经存在的云端会话
                        ormchpikGcmflTHU?.forEach { xMeiNXsxexQoqySe in
                            switch xMeiNXsxexQoqySe.lastMessage.conversationType! {
                            case YIMEnum_ConversationType.P2P:
                                let IYfxgmQIzqRJWEUV = (xMeiNXsxexQoqySe.lastMessage.from == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG ? xMeiNXsxexQoqySe.lastMessage.to : xMeiNXsxexQoqySe.lastMessage.from)
                                for (IdTnUPClSPFWmlSc, tsoNMEswtkBRsRKp) in etjOVteRPjPtfhhi!.enumerated().reversed() {
                                    if (tsoNMEswtkBRsRKp["conversationID"] as! String) == IYfxgmQIzqRJWEUV { etjOVteRPjPtfhhi!.remove(at: IdTnUPClSPFWmlSc) }
                                }
                            case YIMEnum_ConversationType.Team:
                                let IYfxgmQIzqRJWEUV = xMeiNXsxexQoqySe.lastMessage.to
                                for (IdTnUPClSPFWmlSc, tsoNMEswtkBRsRKp) in etjOVteRPjPtfhhi!.enumerated().reversed() {
                                    if (tsoNMEswtkBRsRKp["conversationID"] as! String) == IYfxgmQIzqRJWEUV { etjOVteRPjPtfhhi!.remove(at: IdTnUPClSPFWmlSc) }
                                }
                            default: break
                            }
                        }
                        //将本地没有的云端会话，把消息同步下来
                        etjOVteRPjPtfhhi!.forEach { xMeiNXsxexQoqySe in
                            fZwNztHkPUvazdeo.YEdpUIviIcRKaHeV.FMCEiTfVplJHuoRQ(
                                uwnLgFlhpyfCLJAx: YIMEnum_ConversationType(rawValue: xMeiNXsxexQoqySe["conversationType"] as! String)!,
                                IYfxgmQIzqRJWEUV: xMeiNXsxexQoqySe["conversationID"] as! String,
                                KLywTOzhcQSiFAmi: NbDnvbpESqnqDInl.SoORWivnNfUskmhc.GJKvugccbQatkozy
                            ) { mKUIzAxlvBGUVfVk, zpAppbgYcokukiGf in
                                if mKUIzAxlvBGUVfVk {
                                    var IdTnUPClSPFWmlSc = 0
                                    let qFAvntjgxjpeObCk = zpAppbgYcokukiGf!.reversed()
                                    qFAvntjgxjpeObCk.forEach {
                                        jlvTeJlkZyPilZcK(GZRevkeIIdHLwXxe: $0, kaDklCkbYfRntgZy: false) { mKUIzAxlvBGUVfVk in
                                            if !mKUIzAxlvBGUVfVk { return }
                                            let mXlTEoCuvqhGCSmB = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.ZOviHOAzCiIvfLxT(_YIMTable_Conversation.self, gcspUzKnQvCPVWDj: {
                                                switch YIMEnum_ConversationType(rawValue: xMeiNXsxexQoqySe["conversationType"] as! String)! {
                                                case YIMEnum_ConversationType.P2P:
                                                    ((_YIMTable_Conversation._from == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Conversation._to == xMeiNXsxexQoqySe["conversationID"] as! String) || _YIMTable_Conversation._to == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Conversation._from == xMeiNXsxexQoqySe["conversationID"] as! String) && _YIMTable_Conversation._conversationType == YIMEnum_ConversationType.Team.rawValue
                                                case YIMEnum_ConversationType.Team:
                                                    _YIMTable_Conversation._to == xMeiNXsxexQoqySe["conversationID"] as! String && _YIMTable_Conversation._conversationType == YIMEnum_ConversationType.Team.rawValue
                                                default:
                                                    _YIMTable_Conversation.t_id.isNil()
                                                }
                                            }, tuATquJzrMWXRcKf: {
                                                $0?.first?.unRead = Int("\(xMeiNXsxexQoqySe["unReadCount"]!)")!
                                                return $0
                                            }, mmtvsbscFeDeMSIO: { EevOPNXlgWpEDUXw, iOWRlrkXHKdAMgbh in
                                                EevOPNXlgWpEDUXw.t_id = iOWRlrkXHKdAMgbh.t_id
                                            }, XDbstgapvwDPECiX: _YIMTable_Conversation.__)
                                            if !mXlTEoCuvqhGCSmB { return }
                                            if IdTnUPClSPFWmlSc >= zpAppbgYcokukiGf!.count - 1 {
                                                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                                                    try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.eQTUmWmtELtmLuVV?()
                                                }
                                                let pLPuPjymILJmMTHC = {
                                                    switch YIMEnum_ConversationType(rawValue: xMeiNXsxexQoqySe["conversationType"] as! String)! {
                                                    case YIMEnum_ConversationType.P2P:
                                                        ((_YIMTable_Conversation._from == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Conversation._to == xMeiNXsxexQoqySe["conversationID"] as! String)
                                                         || (_YIMTable_Conversation._to == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Conversation._from == xMeiNXsxexQoqySe["conversationID"] as! String))
                                                        && (_YIMTable_Conversation._conversationType == xMeiNXsxexQoqySe["conversationType"] as! String)
                                                    case YIMEnum_ConversationType.Team:
                                                        _YIMTable_Conversation._to == xMeiNXsxexQoqySe["conversationID"] as! String
                                                        && _YIMTable_Conversation._conversationType == xMeiNXsxexQoqySe["conversationType"] as! String
                                                    default:
                                                        _YIMTable_Conversation.t_id.isNil()
                                                    }
                                                }
                                                let ufiMwtSGkwkOKTnp = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.RhNOPYfGfjrwMIPu(
                                                    _YIMTable_Conversation.self,
                                                    gcspUzKnQvCPVWDj: pLPuPjymILJmMTHC,
                                                    XDbstgapvwDPECiX: _YIMTable_Conversation._time
                                                )
                                                if ufiMwtSGkwkOKTnp == nil {
                                                    return
                                                }
                                                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                                                    try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.SStXrjMtBhxsVxWV?(ufiMwtSGkwkOKTnp!.map { YIMConversation(xMeiNXsxexQoqySe: $0) })
                                                }
                                            }
                                            IdTnUPClSPFWmlSc += 1
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? self.jqKudqmHVDVUDDZz?(YIMResult(VnJfdRrzZmdnJmsc: .Success, EmqetgaKELbCTYMP: "success"))
            }
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                self.jqKudqmHVDVUDDZz = nil
            }
            //将历史的发送中消息，置为失败状态
            let _ = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.ZOviHOAzCiIvfLxT(_YIMTable_Message.self, gcspUzKnQvCPVWDj: {
                _YIMTable_Message.messageState == YIMEnum_MessageState.Sending.rawValue
            }, tuATquJzrMWXRcKf: {
                $0?.forEach { $0.messageState = YIMEnum_MessageState.Fail.rawValue }
                return $0
            }, mmtvsbscFeDeMSIO: { EevOPNXlgWpEDUXw, iOWRlrkXHKdAMgbh in
                EevOPNXlgWpEDUXw.t_id = iOWRlrkXHKdAMgbh.t_id
            }, XDbstgapvwDPECiX: _YIMTable_Message.__)
            fZwNztHkPUvazdeo.rDswoxpKBaqbcUtn.TEHrCcQWLqKUUweb { ormchpikGcmflTHU in
                if ormchpikGcmflTHU == nil { return }
                for xMeiNXsxexQoqySe in ormchpikGcmflTHU! {
                    let _ = fZwNztHkPUvazdeo.rDswoxpKBaqbcUtn.gTORhrTDtqcJUNpY(uwnLgFlhpyfCLJAx: xMeiNXsxexQoqySe.lastMessage.conversationType, IYfxgmQIzqRJWEUV: xMeiNXsxexQoqySe.lastMessage.getConversationID())
                }
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                    try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.eQTUmWmtELtmLuVV?()
                }
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                    try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.NkHBdSgXsWnSDTLg?(ormchpikGcmflTHU!)
                }
            }
        case "conversation_top_update":
            let rbtEkWTTnlkPCykk = (EeqbYNIBaZfkqYaF["conversationTops"] as! NSArray).map { $0 as! String }
            NbDnvbpESqnqDInl.rbtEkWTTnlkPCykk = rbtEkWTTnlkPCykk
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.eQTUmWmtELtmLuVV?()
            }
            if fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.NkHBdSgXsWnSDTLg != nil {
                fZwNztHkPUvazdeo.rDswoxpKBaqbcUtn.TEHrCcQWLqKUUweb { ormchpikGcmflTHU in
                    if ormchpikGcmflTHU == nil { return }
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                        try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.NkHBdSgXsWnSDTLg?(ormchpikGcmflTHU!)
                    }
                }
            }
        case "disturbs_p2p_update":
            let CrqtQKnPpOIPqGjt = (EeqbYNIBaZfkqYaF["disturbs_p2p"] as! NSArray).map { $0 as! String }
            NbDnvbpESqnqDInl.CrqtQKnPpOIPqGjt = CrqtQKnPpOIPqGjt
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.eQTUmWmtELtmLuVV?()
            }
            if fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.NkHBdSgXsWnSDTLg != nil {
                fZwNztHkPUvazdeo.rDswoxpKBaqbcUtn.TEHrCcQWLqKUUweb { ormchpikGcmflTHU in
                    if ormchpikGcmflTHU == nil { return }
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                        try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.NkHBdSgXsWnSDTLg?(ormchpikGcmflTHU!)
                    }
                }
            }
        case "disturbs_team_update":
            let vBnlRsjXyYsjAiyP = (EeqbYNIBaZfkqYaF["disturbs_team"] as! NSArray).map { $0 as! String }
            NbDnvbpESqnqDInl.vBnlRsjXyYsjAiyP = vBnlRsjXyYsjAiyP
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.eQTUmWmtELtmLuVV?()
            }
            if fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.NkHBdSgXsWnSDTLg != nil {
                fZwNztHkPUvazdeo.rDswoxpKBaqbcUtn.TEHrCcQWLqKUUweb { ormchpikGcmflTHU in
                    if ormchpikGcmflTHU == nil { return }
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                        try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.NkHBdSgXsWnSDTLg?(ormchpikGcmflTHU!)
                    }
                }
            }
        case "kick":
            fZwNztHkPUvazdeo.kKZHQgqVvWvEzcze.DASFOrpmVNSuuhGj()
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.XBgpCrYXyimOqEjN?(YIMResult(VnJfdRrzZmdnJmsc: .Kick, EmqetgaKELbCTYMP: "Kicked by \(EeqbYNIBaZfkqYaF["device"]!) device"))
            }
        case "kick_room":
            let tErCIvYmyunOPvLc = EeqbYNIBaZfkqYaF["roomID"] as! String
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.JouqiwQlCvEBZSfR?(tErCIvYmyunOPvLc)
            }
        case "close_room":
            let tErCIvYmyunOPvLc = EeqbYNIBaZfkqYaF["roomID"] as! String
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.BUgXudieTugynErU?(tErCIvYmyunOPvLc)
            }
        case "message", "message_sync":
            let zpAppbgYcokukiGf = NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.IYMCIgmwfHIBQjIX(EeqbYNIBaZfkqYaF["messages"], [_YIMTable_Message].self)!.map{ YIMMessage(GZRevkeIIdHLwXxe: $0) }
            zpAppbgYcokukiGf.forEach { GZRevkeIIdHLwXxe in
                let IYfxgmQIzqRJWEUV = GZRevkeIIdHLwXxe.getConversationID()
                let pLPuPjymILJmMTHC = {
                    switch GZRevkeIIdHLwXxe.conversationType! {
                    case YIMEnum_ConversationType.P2P:
                        ((_YIMTable_Conversation._from == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Conversation._to == IYfxgmQIzqRJWEUV)
                         || (_YIMTable_Conversation._to == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Conversation._from == IYfxgmQIzqRJWEUV))
                        && _YIMTable_Conversation._conversationType == GZRevkeIIdHLwXxe.conversationType.rawValue
                    case YIMEnum_ConversationType.Team:
                        _YIMTable_Conversation._to == IYfxgmQIzqRJWEUV
                        && _YIMTable_Conversation._conversationType == GZRevkeIIdHLwXxe.conversationType.rawValue
                    case YIMEnum_ConversationType.ChatRoom:
                        _YIMTable_Conversation._conversationType == GZRevkeIIdHLwXxe.conversationType.rawValue
                    default:
                        _YIMTable_Conversation.t_id.isNil()
                    }
                }
                var ufiMwtSGkwkOKTnp = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.RhNOPYfGfjrwMIPu(
                    _YIMTable_Conversation.self,
                    gcspUzKnQvCPVWDj: pLPuPjymILJmMTHC,
                    XDbstgapvwDPECiX: _YIMTable_Conversation._time
                )
                if ufiMwtSGkwkOKTnp == nil {
                    return
                }
                jlvTeJlkZyPilZcK(GZRevkeIIdHLwXxe: GZRevkeIIdHLwXxe, kaDklCkbYfRntgZy: kEZOdhLcNmJFYywX == "message") { mKUIzAxlvBGUVfVk in
                    if !mKUIzAxlvBGUVfVk { return }
                    let ZMbwDIvEfxQvwQMb = ufiMwtSGkwkOKTnp!.isEmpty
                    ufiMwtSGkwkOKTnp = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.RhNOPYfGfjrwMIPu(
                        _YIMTable_Conversation.self,
                        gcspUzKnQvCPVWDj: pLPuPjymILJmMTHC,
                        XDbstgapvwDPECiX: _YIMTable_Conversation._time
                    )
                    if ufiMwtSGkwkOKTnp == nil {
                        return
                    }
                    if [YIMEnum_ConversationType.P2P, YIMEnum_ConversationType.ChatRoom].contains(GZRevkeIIdHLwXxe.conversationType) {
                        if ZMbwDIvEfxQvwQMb {
                            //新增的会话
                            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                                try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.SStXrjMtBhxsVxWV?(ufiMwtSGkwkOKTnp!.map { YIMConversation(xMeiNXsxexQoqySe: $0) })
                            }
                        } else {
                            //原有的会话
                            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                                try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.NkHBdSgXsWnSDTLg?(ufiMwtSGkwkOKTnp!.map { YIMConversation(xMeiNXsxexQoqySe: $0) })
                            }
                        }
                    }
                }
            }
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.eQTUmWmtELtmLuVV?()
            }
        case "broadcast":
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.WsyxCKtmLvJidtlp?(NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.IYMCIgmwfHIBQjIX(EeqbYNIBaZfkqYaF["messages"], YIMBroadcastMessage.self)!)
            }
        case "notification":
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.xLcRiczleBlqkCdn?(NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.IYMCIgmwfHIBQjIX(EeqbYNIBaZfkqYaF["messages"], YIMNotificationMessage.self)!)
            }
        case "revoke", "revoke_sync":
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.IYMCIgmwfHIBQjIX(EeqbYNIBaZfkqYaF["messages"], [YIMRevokeMessage].self)?.forEach { GZRevkeIIdHLwXxe in
                if [YIMEnum_ConversationType.P2P, YIMEnum_ConversationType.ChatRoom].contains(GZRevkeIIdHLwXxe.conversationType) {
                    let mutHbqGGkcrRPdCJ = fZwNztHkPUvazdeo.YEdpUIviIcRKaHeV.isgJTwrjAjJefSGB(uwnLgFlhpyfCLJAx: GZRevkeIIdHLwXxe.conversationType,                 cWSIMxBBOoVwGhZm: GZRevkeIIdHLwXxe.messageID)
                    if !mutHbqGGkcrRPdCJ { return }
                    let drotiWAFkowcWbqO = fZwNztHkPUvazdeo.rDswoxpKBaqbcUtn.gTORhrTDtqcJUNpY(uwnLgFlhpyfCLJAx: GZRevkeIIdHLwXxe.conversationType,         IYfxgmQIzqRJWEUV: GZRevkeIIdHLwXxe.conversationID)
                    if !drotiWAFkowcWbqO { return }
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                        try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.eQTUmWmtELtmLuVV?()
                    }
                    let pLPuPjymILJmMTHC = {
                        switch GZRevkeIIdHLwXxe.conversationType! {
                        case YIMEnum_ConversationType.P2P:
                            ((_YIMTable_Conversation._from == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Conversation._to == GZRevkeIIdHLwXxe.conversationID)
                             || (_YIMTable_Conversation._to == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Conversation._from == GZRevkeIIdHLwXxe.conversationID))
                            && (_YIMTable_Conversation._conversationType == GZRevkeIIdHLwXxe.conversationType.rawValue)
                        case YIMEnum_ConversationType.Team:
                            _YIMTable_Conversation._to == GZRevkeIIdHLwXxe.conversationID
                            && _YIMTable_Conversation._conversationType == GZRevkeIIdHLwXxe.conversationType.rawValue
                        default:
                            _YIMTable_Conversation.t_id.isNil()
                        }
                    }
                    let ufiMwtSGkwkOKTnp = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.RhNOPYfGfjrwMIPu(
                        _YIMTable_Conversation.self,
                        gcspUzKnQvCPVWDj: pLPuPjymILJmMTHC,
                        XDbstgapvwDPECiX: _YIMTable_Conversation._time
                    )
                    if ufiMwtSGkwkOKTnp == nil {
                        return
                    }
                    NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                        try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.NkHBdSgXsWnSDTLg?(ufiMwtSGkwkOKTnp!.map { YIMConversation(xMeiNXsxexQoqySe: $0) })
                    }
                }
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                    try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.gDnkPdGwPnIjLGpW?(GZRevkeIIdHLwXxe)
                }
            }
        case "receipt_p2p":
            (EeqbYNIBaZfkqYaF["conversationIDs"] as! NSArray).map { $0 as! String }.forEach { IYfxgmQIzqRJWEUV in
                let mutHbqGGkcrRPdCJ = fZwNztHkPUvazdeo.YEdpUIviIcRKaHeV.SwjLZskphOFqktRN(uwnLgFlhpyfCLJAx: YIMEnum_ConversationType.P2P,         IYfxgmQIzqRJWEUV: IYfxgmQIzqRJWEUV,         IyFwCVRgYzNeLHkj: false)
                if !mutHbqGGkcrRPdCJ { return }
                let drotiWAFkowcWbqO = fZwNztHkPUvazdeo.rDswoxpKBaqbcUtn.gTORhrTDtqcJUNpY(uwnLgFlhpyfCLJAx: .P2P, IYfxgmQIzqRJWEUV: IYfxgmQIzqRJWEUV)
                if !drotiWAFkowcWbqO { return }
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                    try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.eQTUmWmtELtmLuVV?()
                }
                let pLPuPjymILJmMTHC = {
                    ((_YIMTable_Conversation._from == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Conversation._to == IYfxgmQIzqRJWEUV)
                     || (_YIMTable_Conversation._to == NbDnvbpESqnqDInl.ZOjIzOztbVARDuqG! && _YIMTable_Conversation._from == IYfxgmQIzqRJWEUV))
                    && (_YIMTable_Conversation._conversationType == YIMEnum_ConversationType.P2P.rawValue)
                }
                let ufiMwtSGkwkOKTnp = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.RhNOPYfGfjrwMIPu(
                    _YIMTable_Conversation.self,
                    gcspUzKnQvCPVWDj: pLPuPjymILJmMTHC,
                    XDbstgapvwDPECiX: _YIMTable_Conversation._time
                )
                if ufiMwtSGkwkOKTnp == nil {
                    return
                }
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                    try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.NkHBdSgXsWnSDTLg?(ufiMwtSGkwkOKTnp!.map { YIMConversation(xMeiNXsxexQoqySe: $0) })
                }
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                    try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.hEeTkyFyliKlUfDp?(IYfxgmQIzqRJWEUV)
                }
            }
        case "receipt_team":
            (EeqbYNIBaZfkqYaF["conversationIDs"] as! NSArray).map { $0 as! String }.forEach { IYfxgmQIzqRJWEUV in
                let mutHbqGGkcrRPdCJ = fZwNztHkPUvazdeo.YEdpUIviIcRKaHeV.SwjLZskphOFqktRN(uwnLgFlhpyfCLJAx: YIMEnum_ConversationType.Team,         IYfxgmQIzqRJWEUV: IYfxgmQIzqRJWEUV, IyFwCVRgYzNeLHkj: false)
                if !mutHbqGGkcrRPdCJ { return }
                let drotiWAFkowcWbqO = fZwNztHkPUvazdeo.rDswoxpKBaqbcUtn.gTORhrTDtqcJUNpY(uwnLgFlhpyfCLJAx: .Team, IYfxgmQIzqRJWEUV: IYfxgmQIzqRJWEUV)
                if !drotiWAFkowcWbqO { return }
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                    try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.eQTUmWmtELtmLuVV?()
                }
                let pLPuPjymILJmMTHC = {
                    _YIMTable_Conversation._to == IYfxgmQIzqRJWEUV
                    && _YIMTable_Conversation._conversationType == YIMEnum_ConversationType.Team.rawValue
                }
                let ufiMwtSGkwkOKTnp = NbDnvbpESqnqDInl.KxuJgneUsZVEQtvM.RhNOPYfGfjrwMIPu(
                    _YIMTable_Conversation.self,
                    gcspUzKnQvCPVWDj: pLPuPjymILJmMTHC,
                    XDbstgapvwDPECiX: _YIMTable_Conversation._time
                )
                if ufiMwtSGkwkOKTnp == nil {
                    return
                }
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                    try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.NkHBdSgXsWnSDTLg?(ufiMwtSGkwkOKTnp!.map { YIMConversation(xMeiNXsxexQoqySe: $0) })
                }
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                    try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.hEeTkyFyliKlUfDp?(IYfxgmQIzqRJWEUV)
                }
            }
        case "receipt_room":
            (EeqbYNIBaZfkqYaF["conversationIDs"] as! NSArray).map { $0 as! String }.forEach { IYfxgmQIzqRJWEUV in
                NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                    try? fZwNztHkPUvazdeo.wrrBUnSAzBPGBWIC.hEeTkyFyliKlUfDp?(IYfxgmQIzqRJWEUV)
                }
            }
        case "event_online":
            let UhzaNhigkZjxYKFZ = EeqbYNIBaZfkqYaF["user"] as! String
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? fZwNztHkPUvazdeo.NKBRHVWrtACVYZIX.qullakzWowrBAiuC?(UhzaNhigkZjxYKFZ, .Online)
            }
        case "event_offline":
            let UhzaNhigkZjxYKFZ = EeqbYNIBaZfkqYaF["user"] as! String
            NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.CzkztFjgxzeSorYu {
                try? fZwNztHkPUvazdeo.NKBRHVWrtACVYZIX.qullakzWowrBAiuC?(UhzaNhigkZjxYKFZ, .Offline)
            }
        case "update_user":
            NbDnvbpESqnqDInl.ZPyrCbzOlbdctqkw = NbDnvbpESqnqDInl.zYOvKsmnWpOUpLXr.IYMCIgmwfHIBQjIX(EeqbYNIBaZfkqYaF["user"], YIMUser.self)
        default: break
        }
        objc_sync_exit(gcDwQgisPaYpamBp)
    }
}
